﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using ZCMS.Configuration;
using ZCMS.Web;

namespace ZCMS.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class ZCMSDbContextFactory : IDesignTimeDbContextFactory<ZCMSDbContext>
    {
        public ZCMSDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<ZCMSDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            ZCMSDbContextConfigurer.Configure(builder, configuration.GetConnectionString(ZCMSConsts.ConnectionStringName));

            return new ZCMSDbContext(builder.Options);
        }
    }
}
